(() => {
	let ele = {};

	ele.redmoney = $('#redmoney');
	ele.withdrawal = $('#withdrawal');

	let alipay_name = getCookie('alipay_name');
	let alipay_account = getCookie('alipay_account');
	ele.isshow = document.getElementById('isshow')

	ele.collect = $('#collect')
	ele.zhihao = $('#zhihao')
	if (alipay_name != 'null' && alipay_name != '') {
		ele.isshow.style.display = 'none'
		ele.collect.style.display = 'block'
		ele.zhihao.innerHTML = alipay_account
	} else {
		ele.isshow.style.display = 'block'
		ele.collect.style.display = 'none'
	}

	let balance = parseFloat(getCookie('red_envelope')) || '0.00';

	init();

	function init() {
		getUserInfo(res => {
			balance = res.red_envelope;
			ele.redmoney.innerText = res.red_envelope;
		});
	}


	// 点击提现
	ele.withdrawal.onclick = () => {
		if (1000 > parseFloat(balance)) {
			openTips('余额不足,不能提现')
		}
		else {
			sendWithdrawal();
		}
	}

	// 发送提现请求
	function sendWithdrawal() {
		let token = getCookie('token');
		let userid = getCookie('userid');
		// let phone_type = getClientType()
		ajax({
			url: API_PATH.CASH,
			method: 'POST',
			header: {
				Authorization: token
			},
			data: {
				type: 2,
				money: 1000,
			},
			success: res => {
				if (res.code == 1) {
					init();
				}
				openTips(res.msg);
			}
		});
	}


})();
